home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume17 / iozone / part01 next >
Encoding:
Internet Message Format  |  1991-03-23  |  10.8 KB

  1. From: norcott@databs.enet.dec.com (Bill Norcott)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i065:  iozone - sequential file I/O benchmark fo UNIX, VMS & DOS, Part01/01
  4. Message-ID: <1991Mar22.212846.16835@sparky.IMD.Sterling.COM>
  5. Date: 22 Mar 91 21:28:46 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: d99c130b 0289099b 383d6934 09c70654
  8.  
  9. Submitted-by: Bill Norcott <norcott@databs.enet.dec.com>
  10. Posting-number: Volume 17, Issue 65
  11. Archive-name: iozone/part01
  12.  
  13. Attached is a benchmark called IOzone which I have written.  It was inspired
  14. by Alvin Park's IOstone benchmark (which tests random access I/O).  IOzone
  15. tests sequential file I/O using the C language.  It writes, then reads, a
  16. sequential file of fixed length records, and measures the read & write
  17. rates in bytes per second.  The default is to create a 1 megabyte file 
  18. consisting of 2048, 512-byte records -- however, these parameters can be
  19. changed from the command line.  On UNIX systems, the results will be influenced
  20. by the effect of the buffer cache -- however, we can largely negate the
  21. effect of caching by using a file size greater than twice the size of the
  22. cache.  This will allow a fairer comparison between various disk drives 
  23. attached to the system.  IOzone IS NOT a direct test of disk performance.  Its
  24. results are a combination of disk speed, CPU speed, amount of cache, and the
  25. efficiency of the C compiler & runtime library.  This is also true of IOstone,
  26. in fact I intend this program as a companion piece to IOstone. 
  27.  
  28. This benchmark is portable and has been tested on these operating systems:
  29.     
  30.     VAX/VMS V5.4
  31.     Ultrix V4.1
  32.     MS-DOS V3.1
  33.     OSF/1
  34.  
  35. IOZONE.C is free and in the public domain.  I would appreciate your
  36. comment and test results.
  37.  
  38. Bill Norcott    (Bill.Norcott.nuo.mts.dec.com)
  39.  
  40. ------------------------------   CUT HERE ----------------------------- 
  41. #! /bin/sh
  42. # This is a shell archive.  Remove anything before this line, then feed it
  43. # into a shell via "sh file" or similar.  To overwrite existing files,
  44. # type "sh file -c".
  45. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  46. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  47. # Contents:  iozone.c
  48. # Wrapped by kent@sparky on Fri Mar 22 15:25:03 1991
  49. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  50. echo If this archive is complete, you will see the following message:
  51. echo '          "shar: End of archive."'
  52. if test -f 'iozone.c' -a "${1}" != "-c" ; then 
  53.   echo shar: Will not clobber existing file \"'iozone.c'\"
  54. else
  55.   echo shar: Extracting \"'iozone.c'\" \(7723 characters\)
  56.   sed "s/^X//" >'iozone.c' <<'END_OF_FILE'
  57. X/*
  58. X*    "IO Zone" Benchmark Program
  59. X*
  60. X*    Author:    Bill Norcott (Bill.Norcott@nuo.mts.dec.com)
  61. X*        4 Dunlap Drive
  62. X*        Nashua, NH  03060
  63. X*
  64. X*  "Copyright 1991,   William D. Norcott
  65. X*  This is free software.  License to freely use and distribute this
  66. X*  software is hereby granted by the author, subject to the condition
  67. X*  that this copyright notice remains intact."
  68. X*
  69. X* "This test writes a 4 MEGABYTE sequential file in 512 byte chunks, then
  70. X* rewinds it  and reads it back.  [The size of the file should be
  71. X* big enough to factor out the effect of any disk cache.]
  72. X*       
  73. X* The file is written (filling any cache buffers), and then read.  If the
  74. X* cache is >= 4 MB, then most if not all the reads will be satisfied from
  75. X* the cache.  However, if it is less than or equal to 2 MB, then NONE of
  76. X* the reads will be satisfied from the cache.  This is becase after the 
  77. X* file is written, a 2 MB cache will contain the upper 2 MB of the test
  78. X* file, but we will start reading from the beginning of the file (data
  79. X* which is no longer in the cache)
  80. X* In order for this to be a fair test, the length of the test file must
  81. X* be AT LEAST 2X the amount of disk cache memory for your system.  If
  82. X* not, you are really testing the speed at which your CPU can read blocks
  83. X* out of the cache (not a fair test)
  84. X*       
  85. X* IOZONE does NOT test the raw I/O speed of your disk or system.  It
  86. X* tests the speed of sequential I/O to actual files.  Therefore, this
  87. X* measurement factors in the efficiency of you machines file system,
  88. X* operating system, C compiler, and C runtime library.  It produces a 
  89. X* measurement which is the number of bytes per second that your system
  90. X* can read or write to a file.  For UNIX systems I call fsync() to force
  91. X* the writes to disk.  This gives a test of the time it takes to
  92. X* actually get data onto the disk.
  93. X*       
  94. X* This program has been ported and tested on the following computer
  95. X* operating systems:
  96. X*    VAX/VMS V5.4, Ultrix V4.1, OSF/1 and MS-DOS 3.3"
  97. X*       
  98. X* --- MODIFICATION HISTORY:
  99. X*
  100. X*   3/7/91 William D. Norcott (Bill.Norcott@nuo.mts.dec.com)
  101. X*        created
  102. X*   3/22/91 Bill Norcott    tested on OSF/1 ... it works
  103. X*
  104. X*/
  105. X#ifdef    __MSDOS__        /* Turbo C define this way for PCs... */
  106. X#define    MSDOS            /* Microsoft C defines this */
  107. X#endif
  108. X/* VMS and MS-DOS both have ANSI C compilers and use rand()/srand() */
  109. X#ifdef    VMS_POSIX
  110. X#undef   VMS
  111. X#define    ANSI_RANDOM    1
  112. X#endif
  113. X#ifdef    MSDOS
  114. X#define    ANSI_RANDOM    1
  115. X#endif
  116. X
  117. X#if defined(VMS)
  118. X#define    ANSI_RANDOM    1
  119. X#include    <math.h>
  120. X#include    <unixio.h>
  121. X#include    <ssdef.h>
  122. X#include    <file.h>
  123. X
  124. X#elif defined(MSDOS)
  125. X#include <fcntl.h>
  126. X#elif defined(unix)
  127. X#include <sys/file.h>
  128. X#include <limits.h>
  129. X#endif
  130. X
  131. X#define MEGABYTES 1            /* number of megabytes in file */
  132. X#define RECLEN 512            /* number of bytes in a record */
  133. X#define FILESIZE (MEGABYTES*1024*1024)    /*size of file in bytes*/
  134. X#define NUMRECS FILESIZE/RECLEN        /* number of records */
  135. X#define MAXBUFFERSIZE 16*1024        /*maximum buffer size*/
  136. X#define TOOFAST 10
  137. X#define USAGE  "\tUsage:\tiozone [megabytes] [record_length] [[path]filename]\n\n"
  138. X#define THISVERSION "V1.01"
  139. X
  140. X/* Define only one of the following two.*/
  141. X/*#define NOTIME        define if no time function in library*/
  142. X#define TIME                /*Use time(2)function*/
  143. X
  144. X#define MAXNAMESIZE 1000                /* max # of characters in filename */
  145. X
  146. Xmain(argc,argv) 
  147. X      int argc;
  148. X     char *argv[];
  149. X{
  150. Xint fd;
  151. Xchar filename [MAXNAMESIZE];            /* name of temporary file */
  152. X#ifdef    VMS
  153. Xchar *default_filename="iozone_temp_file"; /*default name of temporary file*/
  154. X#else
  155. X#ifdef    MSDOS
  156. Xchar *default_filename="iozone.tmp"; /*default name of temporary file*/
  157. X#else 
  158. Xchar *default_filename="/tmp/iozone_temp_file"; /*default name of temporary file*/
  159. X#endif
  160. X#endif 
  161. X#ifdef    MSDOS
  162. Xchar *buffer; 
  163. X#else
  164. Xchar buffer [MAXBUFFERSIZE];        /*a temporary data buffer*/
  165. X#endif
  166. Xint i, status;
  167. Xunsigned long megabytes = MEGABYTES, goodmegs;
  168. Xunsigned long reclen = RECLEN, goodrecl;
  169. Xunsigned long filesize = FILESIZE;
  170. Xunsigned long numrecs = NUMRECS;
  171. X
  172. X#ifdef TIME
  173. X long time();
  174. X long starttime1, starttime2;
  175. X long writetime;
  176. X long totaltime;
  177. X
  178. X#endif
  179. X
  180. X#ifdef MSDOS
  181. X  buffer = (char *) malloc(MAXBUFFERSIZE);
  182. X#endif
  183. X
  184. X  printf("\n\tIOZONE: Performance Test of Sequential File I/O  --  %s\n",
  185. X          THISVERSION);
  186. X  printf("\t\tBy Bill Norcott\n\n");
  187. X
  188. X  strcpy(filename,default_filename);
  189. X  switch (argc) {
  190. X    case 1:       /* no args, take all defaults */
  191. X      printf(USAGE);
  192. X    break;
  193. X    case 2:     /* <megabytes|filename> */
  194. X    i = atoi(argv[1]); if (i) {
  195. X      megabytes = i;
  196. X    } else {
  197. X      strcpy(filename,argv[1]);
  198. X        }
  199. X    break;
  200. X    case 3:     /* <megabytes> <reclen|filename> */
  201. X    filesize = atoi(argv[1]);
  202. X    i = atoi(argv[2]); if(i) {
  203. X      reclen = (unsigned) i;
  204. X    } else {
  205. X      strcpy(filename,argv[2]);
  206. X    }
  207. X    break;
  208. X    case 4:     /* <megabytes> <reclen> <filename> */
  209. X    filesize = atoi(argv[1]);
  210. X    reclen = atoi(argv[2]);
  211. X    strcpy(filename,argv[3]);
  212. X    break;
  213. X    default:
  214. X      printf(USAGE);
  215. X      exit(1);
  216. X
  217. X  }
  218. X  printf("\tSend comments to:\tBill.Norcott@nuo.mts.dec.com\n\n");
  219. X
  220. X  filesize = megabytes*1024*1024;
  221. X  numrecs = filesize/reclen;
  222. X  if (reclen >  MAXBUFFERSIZE) {
  223. X    printf("Error: Maximum record length is %d bytes\n", MAXBUFFERSIZE);
  224. X    }
  225. X  printf("\tIOZONE writes a %ld Megabyte sequential file consisting of\n",
  226. X    megabytes);
  227. X  printf("\t%ld records which are each %ld bytes in length.\n",
  228. X    numrecs, reclen);
  229. X  printf("\tIt then reads the file.  It prints the bytes-per-second\n");
  230. X  printf("\trate at which the computer can read and write files.\n\n");
  231. X  printf("\nWriting the %ld Megabyte file, '%s'...", megabytes, filename);
  232. X
  233. X#ifdef TIME
  234. X    starttime1 = time(0);
  235. X#endif
  236. X    if((fd = creat(filename, 0640))<0){
  237. X        printf("Cannot create temporary file\n");
  238. X        exit(1);
  239. X    }
  240. X    for(i=0; i<numrecs; i++){
  241. X        write(fd, buffer, (unsigned) reclen);
  242. X    }
  243. X
  244. X#ifdef TIME
  245. X    writetime = time(0) - starttime1;
  246. X    printf("%d seconds", writetime);
  247. X#endif
  248. X    close(fd);
  249. X#ifdef VMS
  250. X    if((fd = open(filename, O_RDONLY, 0640))<0){
  251. X        printf("Cannot open temporary file for read\n");
  252. X        exit(1);
  253. X#elif defined(MSDOS)
  254. X    if((fd = open(filename, O_RDONLY, 0640))<0){
  255. X        printf("Cannot open temporary file for read\n");
  256. X        exit(1);
  257. X#else
  258. X    if((fd = open(filename, O_RDONLY))<0){
  259. X        printf("Cannot open temporary file for read\n");
  260. X        exit(1);
  261. X#endif
  262. X    }
  263. X
  264. X            /*start timing*/
  265. X#ifdef NOTIME
  266. X    printf("start timing\n");
  267. X#endif
  268. X
  269. X    printf("\nReading the file...");
  270. X    starttime2 = time(0);
  271. X   for(i=0; i<numrecs; i++) {
  272. X    if(read(fd, buffer, (unsigned) reclen) < 0)
  273. X        perror("Read error");
  274. X    }
  275. X#ifdef NOTIME
  276. X    printf("stop timing\n");
  277. X#endif
  278. X#ifdef TIME
  279. X    totaltime = time(0) - starttime2;
  280. X
  281. X    printf("%d seconds\n", totaltime);
  282. X    if(totaltime!=0)
  283. X    {   
  284. X        printf("\nIOZONE performance measurements:\n");
  285. X        printf("\t%ld bytes/second for writing the file\n",
  286. X         (long) ((numrecs*reclen)/writetime) );
  287. X        printf("\t%ld bytes/second for reading the file\n",
  288. X        (long) ((numrecs*reclen)/totaltime) );
  289. X        if (totaltime < TOOFAST) {
  290. X        goodmegs = (TOOFAST/totaltime)*2*megabytes;
  291. X        printf("\nThis machine is fast (or is using a disk cache)!\n");
  292. X        printf("You will get a more accurate measure of its\n");
  293. X        printf("performance by re-running IOZONE using the command:\n");
  294. X        printf("\n\tiozone %d ", goodmegs);
  295. X        printf("\t(i.e., file size = %d megabytes)\n", goodmegs);
  296. X        }
  297. X    } else {
  298. X        goodrecl = reclen/2;
  299. X        printf("\nI/O error during read.  Try again with the command:\n");
  300. X        printf("\n\tiozone %d %d ",megabytes, (int) goodrecl);
  301. X        printf("\t(i.e. record size = %d bytes)\n", (int) goodrecl);
  302. X    }
  303. X#endif
  304. X    close(fd);
  305. X#ifndef VMS
  306. X    unlink(filename);    /* delete the file */
  307. X                    /*stop timer*/
  308. X#endif
  309. X#ifdef    MSDOS
  310. X    free(buffer);        /* deallocate the memory */
  311. X#endif
  312. X#ifdef VMS
  313. Xreturn SS$_NORMAL;
  314. X#else
  315. Xreturn 0;
  316. X#endif
  317. X}
  318. X
  319. X
  320. END_OF_FILE
  321.   if test 7723 -ne `wc -c <'iozone.c'`; then
  322.     echo shar: \"'iozone.c'\" unpacked with wrong size!
  323.   fi
  324.   # end of 'iozone.c'
  325. fi
  326. echo shar: End of archive.
  327. exit 0
  328. exit 0 # Just in case...
  329. -- 
  330. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  331. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  332. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  333. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  334.